home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
varia
/
interp18.lha
/
interp-1.8
/
Symbol.h
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-22
|
4KB
|
130 lines
// -*- C++ -*- Symbol.h -- the Class declaration for the class Symbol.
// Copyright (C) 1989 Carey Richard Murphey.
// (rich@rice.edu) 5310 Rutherglenn, Houston, TX 77096
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 1, or (at your option)
// any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifndef _Symbol_h_
#pragma once
#define _Symbol_h_ 1
#include <String.h>
#include "Table.defs.h"
typedef double (t_func)(double arg); // pointer to function returning double.
class Symbol // a generic symbol.
{
protected:
union {
double * double_p; /* pointer to a floating point variable */
int * int_p; /* pointer to an integer variable */
t_func * t_func_p; /* pointer to a function */
} v; /* change this to an unnamed union later */
public:
Symbol () {}
virtual int type () = 0; // every subclass must define it's type.
virtual ostream& echo (ostream& Stream) = 0; // and echo itself.
virtual void assign (double p);
virtual void assign (int p);
virtual operator double ();
virtual operator int ();
virtual double func (double p);
friend ostream& operator << (ostream& Stream, Symbol* p);
};
// a user defined or builtin double precision number.
class Double_Pointer : public Symbol
{
public:
Double_Pointer (double p)
: Symbol () {v.double_p = new double; *v.double_p = p;}
Double_Pointer (double* p)
: Symbol () {v.double_p = p;}
virtual void assign (double p);
virtual void assign (int p);
operator double ();
operator int () ;
int type ();
ostream& echo (ostream& Stream);
};
// a user defined or builtin integer number.
class Int_Pointer : public Symbol
{
public:
Int_Pointer (int p) : Symbol () {v.int_p = new int; *v.int_p = p;}
Int_Pointer (int* p) : Symbol () {v.int_p = p;}
virtual void assign (double p);
virtual void assign (int p);
operator double ();
operator int ();
int type ();
ostream& echo (ostream& Stream);
};
// a builtin double precision function.
class Function : public Symbol
{
public:
Function (t_func *p) : Symbol () {v.t_func_p = p;}
double func (double p);
int type ();
ostream& echo (ostream& Stream);
void assign (void * p);
};
// a user defined integer function.
class Int_Function : public Symbol
{
protected:
Node *ast; // pointer to the tree holding the function.
StringXPlex *arglist; // an odered list of argument names.
StringXPlex *locals; // an odered list of local variable names.
public:
Int_Function (Node *p) : Symbol () {ast = p;}
double func (double p);
int type ();
ostream& echo (ostream& Stream);
void assign (void * p);
};
// a user defined double precision function.
class Double_Function : public Symbol
{
protected:
Node *ast; // pointer to the tree holding the function.
Table symtab; // the local symbol table holding the arguemnts.
String *arglist; // an array of arguemnt names.
public:
Double_Function (t_func *p) : Symbol () {v.t_func_p = p;}
double func (double p);
int type ();
ostream& echo (ostream& Stream);
void assign (void * p);
};
typedef Symbol * Symbolp;
#if defined(__OPTIMIZE__) && !defined(INLINE)
#define INLINE inline
#include "Symbol.cc"
#ifdef INLINE
#undef INLINE
#endif
#endif
#endif